import { observer, useLocalObservable } from 'mobx-react'
import { useEffect } from 'react'
import { isNullData } from '@/utils'
import { history } from 'umi'
import Store from './store'

export default observer((props: any) => {
    const { id } = history.location.query || {}
    const store = useLocalObservable(() => Store())
    const { getRainbowDetail } = store || {}

    /** 获取生涯彩虹图详情 */
    const getRainbow = () => {
        getRainbowDetail((data: any) => {
            if (isNullData(data)) {
                history.replace(`/rainbow/step1/${id}?id=${id}`)
            } else {
                history.replace(`/rainbow/result/${id}?id=${id}`)
            }
        })
    }
    useEffect(() => {
        getRainbow()
    }, [])

    return <>{props.children}</>
})
